package com.woniu.service.impl;

import com.woniu.entity.Company1;
import com.woniu.mapper.CompanyDao;
import com.woniu.pojo.Company;
import com.woniu.pojo.CompanyExample;
import com.woniu.pojo.StudentExample;
import com.woniu.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

@Service
@Transactional
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    private CompanyDao companyDao;

    @Override
    public List<Company1> findAll(Company company) {
        CompanyExample example = new CompanyExample();
        CompanyExample.Criteria criteria = example.createCriteria();
        if (company != null){
            if (company.getCompanyName() != null && !company.getCompanyName().equals("")){
                criteria.andCompanyNameLike("%" + company.getCompanyName() + "%");
            }
            if (company.getCompanyDetail() != null && !company.getCompanyDetail().equals("")){
                criteria.andCompanyDetailLike("%" + company.getCompanyDetail() + "%");
            }
        }
        return companyDao.selectByExample1(example);
    }

    @Override
    public Company findOne(Integer companyId) {
        return companyDao.selectByPrimaryKey(companyId);
    }

    @Override
    public void add(Company company) {
        companyDao.insert(company);
    }

    @Override
    public void update(Company company) {
        companyDao.updateByPrimaryKey(company);
    }

    @Override
    public void deleteById(Integer companyId) {
        companyDao.deleteByPrimaryKey(companyId);
    }

    @Override
    public void updateById(Company company) {
        companyDao.updateByPrimaryKey(company);
    }

    @Override
    public void deleteByExample(List<Integer> companyIds) {
        CompanyExample example = new CompanyExample();
        example.createCriteria().andCompanyIdIn(companyIds);
        companyDao.deleteByExample(example);
    }

    @Override
    public void updateById1(Company company) {

        companyDao.updateByPrimaryKeySelective(company);
    }

    @Override
    public Integer countByExample() {
        long l = companyDao.countByExample(null);
        return (int)l;
    }
}
